if(!top.$core)top.$core={};
if(!top.$core.getSiteVar)top.$core.getSiteVar=function getSiteVar(name,module) {
	var url='var.php?n='+name;
	if(Object.isString(module)) url+='&m='+module;
	var loader = new Ajax.Request(url,{
								  method:'get',
								  asynchronous:false
								  });
	debugger;
	try{
		return loader.transport.evalJSON();
	}catch(e){
		return loader.transport.responseText;
	}
};
if(!top.$core.getSnippet)top.$core.getSnippet=function getSnippet(query,async,onSuccess,onFailure) {
	var url='snippet.php?'+query,loader;
	var loader = new Ajax.Request(url,{
								  method:'get',
								  asynchronous:async?true:false,
								  onSuccess:typeof onSuccess=='function'?onSuccess:null,
								  onFailure:typeof onFailure=='function'?onFailure:null
								  });
	if(!async) {
		return loader.transport.responseText.stripScripts();
	}
};
if(!top.$core.getEntryData)top.$core.getEntryData=function getEntryData(module,id,asResources) {
	var url='entry.php?m='+module;
	if(typeof id!='undefined') id=parseInt(id);
	if(isFinite(id)) url+='&id='+id;
	if(asResources===true) url+='&raw';
	var json_header,json;
	var loader = new Ajax.Request(url,{
								  method:'get',
								  asynchronous:false,
								  onSuccess:function(transport){
									  json_header = transport.headerJSON;
									  json = transport.responseJSON;
								  }
								  });
	if(json_header && json && json_header.success){
		if(isFinite(id) && json_header.num_entries==1) {
			json=json[0];
		}
		return json;
	}
	return null;
};
if(!top.$core.getURLParams)top.$core.getURLParams = function getURLParams(doc,key) {
	var loc=doc?doc.location:document.location,obj=new Hash();
	loc.search.substr(1).split('&').each(function(v){v=v.split('=');obj.set(v[0],v[1]?v[1]:true);});
	if(key) return obj.get(key);
	else return obj;
};

// Frames Class - Singleton
/*
if(!top.$core.Frames)top.$core.Frames=(function initFrame(){
										function setSingletonMethod(thisObject,instanceObject,name,method) {
											//if(thisObject!=instanceObject) {
												thisObject[name]=method.bind(instanceObject);
											//} else thisObject[name]=method.bind(this);
										};
										function setSingletonProperty(thisObject,instanceObject,name,classPrototype) {
											if(thisObject!=instanceObject) {
												thisObject[name]=instanceObject[name];
											} else {
//												var args=$A(arguments).slice(4);
												thisObject[name]=new classPrototype();
											}
										};
										function registerFrame(name,win,doc,update) {
											var f=this.find(name);
											if(f && update!==true) return null;
											this.frames.set(name,f=$H({name:name,win:win,doc:doc}));
											return f;
										};
										function unregisterFrame(win) {
											var frames=this.frames;
											frames.each(function(f){
															if(f.value.get('win')==win) {
																frames.unset(f.key);
															}
														});
										};
										function findFrame(name) {
											return this.frames.get(name);
										};
										findFrame.doc=function findFrame(name) {
											var f=findFrame.apply(this,arguments);
											return f?f.get('doc'):null;
										};
										findFrame.win=function findFrame(name) {
											var f=findFrame.apply(this,arguments);
											return f?f.get('win'):null;
										};
										function Frames(){
											var inst;
											inst=(Frames.instance instanceof Frames)?Frames.instance:this;
											setSingletonProperty(this,inst,'frames',Hash);
											setSingletonMethod(this,inst,'find',findFrame);
											setSingletonMethod(this,inst,'registerFrame',registerFrame);
											setSingletonMethod(this,inst,'unregisterFrame',unregisterFrame);
											if(!(Frames.instance instanceof Frames)) Frames.instance=this;
										};
										return new Frames();
									})();
*/
if(!top.$core.helper)top.$core.helper=(function(){
	function mpop(c,a){
		var v;
		if(arguments.length==0)return this.pop();
		while(--c>=0){v=this.pop();if(a&&a.push)a.push(v);}
		return this;
	};
	function mshift(c,a){
		var v;
		if(arguments.length==0)return this.shift();
		while(--c>=0){v=this.shift();if(a&&a.push)a.push(v);}
		return this;
	};

	function validateEmail(elementValue){
		/*
		http://www.zparacha.com/validate-email-address-using-javascript-regular-expression/
		Published by Zaheer
		*/
		if(!Object.isString(elementValue) && Object.isString(this))elementValue=this;
		if(Object.isString(elementValue)) {
			var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
			return emailPattern.test(elementValue);
		} else return false;
	}
	function trim(str){if(Object.isString(this))str=this;if(Object.isString(str))return str.replace(/^ +/,"").replace(/ +$/,""); else return null;}
	function toCamelCase(str) {
		if(this instanceof String) str=this;
		str=str.replace(/_/g," ");
		var words=str.split(' '),ret=words[0],i;
		for(i=1;i<words.length;i++)ret+=words[i].capitalize();
		return ret;
	};
	function fromCamelCase(str,capitalize) {
		if(this instanceof String) {
			if(arguments.length==1 && typeof str=='boolean') capitalize=str;
			str=this;
		}
		var ret="",i,j=0,s;
		for(i=0;i<str.length;i++) {
			if(str.charAt(i).match(/[A-Z]/)) {
				s=str.substr(j,i)+' ';
				if(capitalize===true) ret+=s.capitalize();
				else if(capitalize===false)ret+=s.toLowerCase();
				else ret+=s;
				j=i;
			}
		}
		s=str.substr(j,i);
		if(capitalize===true)ret+=s.capitalize();
		else if(capitalize===false)ret+=s.toLowerCase();
		else ret+=s;
		return ret;
	};
	return {toCamelCase:toCamelCase,fromCamelCase:fromCamelCase,validateEmail:validateEmail,mshift:mshift,mpop:mpop,trim:trim};
})();
if(Prototype) {
	$A=$A.wrap(function(p,a){a=p(a);Object.extend(a,{mpop:top.$core.helper.mpop.bind(a),mshift:top.$core.helper.mshift.bind(a)});return a;});
}
var $S=function(s){s=Object.isString(s)?s:(s.toString?s.toString():null);if(s)Object.extend(s,{
																							isEmail:top.$core.helper.validateEmail,
																							toCamelCase:top.$core.helper.toCamelCase,
																							fromCamelCase:top.$core.helper.fromCamelCase
																							});return s;};
if(!String.prototype.trim)String.prototype.trim=top.$core.helper.trim;
String.prototype.isEmail = top.$core.helper.validateEmail;
String.prototype.toCamelCase = top.$core.helper.toCamelCase;
String.prototype.fromCamelCase = top.$core.helper.fromCamelCase;
String.prototype.capitalize = String.prototype.capitalize.wrap(function(proceed,eachWord){
		var re;
		if(eachWord===true)re=/ /g;
		else if(eachWord)re=new RegExp(" |"+eachWord,"g");
		if(eachWord && this.search(re)>-1) {
			return this.split(re).invoke("capitalize").join(" ").trim();
		} else return proceed();
	});
(function(){
	var re=/\\?n=core&load=/;
	$$('head script[src]').findAll(function(s){return s.src.match(re);}).each(function(s) {
		$(s).remove();
		var q=s.src.toQueryParams(),ql=q['load'],ns=[],inc=Try.these(function(){var j=ql.evalJSON();delete j['load'];return j;},function(){return ql.split(',');})||null;
		if(inc&&!Object.isString(inc))inc.each(function ink(m){
			var _ns=ns.join(':');if(_ns)_ns+=':';
			if(Object.isString(m)) {q['n']=_ns+m;Scriptaculous.require('res.php?'+Object.toQueryString(q));}
			else if(m.ns){ns.push(m.ns);if(m.ld&&m.ld.each)m.ld.each(ink);ns.pop();}
		});
	});
})();